package com.cdz.charger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cdz.charger.vo.ChargingSessionVo;
import com.cdz.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.charger.domain.ChargingSession;
import com.cdz.charger.service.IChargingSessionService;
import com.cdz.common.utils.poi.ExcelUtil;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 充电会话Controller
 *
 * @author baefengk2
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/charger/session" )
@Api(tags = "充电会话相关接口" )
public class ChargingSessionController extends BaseController {
    @Autowired
    private IChargingSessionService chargingSessionService;

    /**
     * 查询充电会话列表
     */
    @PreAuthorize("@ss.hasPermi('charger:session:list')" )
    @GetMapping("/list" )
    @ApiOperation(value = "获取充电会话列表" )
    public TableDataInfo<List<ChargingSessionVo>> list(ChargingSession chargingSession) {
        startPage();
        List<ChargingSessionVo> list = chargingSessionService.selectChargingSessionList(chargingSession);
        return getDataTable(list);
    }


    /**
     * 获取充电会话详细信息
     */
    @PreAuthorize("@ss.hasPermi('charger:session:query')" )
    @GetMapping(value = "/{id}" )
    @ApiOperation("获取充电会话详细信息" )
    public R<ChargingSession> getInfo(@ApiParam(value = "充电会话ID" , required = true)
                                   @PathVariable("id" ) Long id) {
                return R.ok(chargingSessionService.selectChargingSessionById(id));
    }

    /**
     * 新增充电会话
     */
    @PreAuthorize("@ss.hasPermi('charger:session:add')" )
    @Log(title = "充电会话" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增充电会话" )
    public AjaxResult add(@ApiParam(value = "充电会话实体" , required = true) @RequestBody ChargingSession chargingSession) {
        return toAjax(chargingSessionService.insertChargingSession(chargingSession));
    }

    /**
     * 修改充电会话
     */
    @PreAuthorize("@ss.hasPermi('charger:session:edit')" )
    @Log(title = "充电会话" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改充电会话" )
    public AjaxResult edit(@ApiParam(value = "充电会话实体" , required = true) @RequestBody ChargingSession chargingSession) {
        return toAjax(chargingSessionService.updateChargingSession(chargingSession));
    }

    /**
     * 删除充电会话
     */
    @PreAuthorize("@ss.hasPermi('charger:session:remove')" )
    @Log(title = "充电会话" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @ApiOperation("删除充电会话" )
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组" ) @PathVariable Long[] ids) {
        return toAjax(chargingSessionService.deleteChargingSessionByIds(ids));
    }
}
